class Solution
{
public:
    long long minCost(vector<int> &nums, int x)
    {
        long long result = 0;
        int n = nums.size();
        for (int i = 0; i < n; ++i)
        {
            result += nums[i];
        }

        vector<int> minPrice = nums;
        for (long long op = 1; op < n; ++op)
        {
            long long tempResult = op * x;
            for (int i = 0; i < n; ++i)
            {
                minPrice[i] = min(minPrice[i], nums[(i + op) % n]);
                tempResult += minPrice[i];
            }
            result = min(result, tempResult);
        }
        return result;
    }
};